/*
 * @(#)Connection.java     Robert Denda
 *
 */

/** 
 * Die Klasse Connection stellt die Funktionalitaeten fuer die Verbindung zwischen Client und
 * Server bereit. 
 *
 * @author 	Robert Denda
 * @version     1.0, 06.09.1997
 * @see Client
 * @see Server
 * @see SimulationClient
 * @see SimulationServer
 *
 */

import java.io.*;
import java.net.*;

public class Connection {
  DataInputStream input;
  DataOutputStream output;
  Socket socket;
  String remoteName;

  public Connection( Socket socket ) {
    this.socket = socket;
    try {
      input = new DataInputStream( socket.getInputStream() );
      output = new DataOutputStream( socket.getOutputStream() );
    } catch( IOException e ) {
    } // try
    remoteName = new String( socket.getInetAddress().getHostName() + " (" + socket.getPort() + ")" );
  } // Connection.Connection
    
  public void write( String s ) throws IOException {
    // try {
    output.writeBytes( s + "\n" );
    // } catch( IOException e ) {
    //  System.out.println("Exception");
    // }
  } // Connection.write

  public String read() {
    String returnValue = null;
    try {
      returnValue = input.readLine();
    } catch( IOException e ) {
    } // try
    return returnValue;
  } // Connection.read
  
  public String getRemoteName() {
    return remoteName;
  } // Connection.getRemoteName

} // Connection
